package cn.ncu.wechat.vo;

import cn.ncu.wechat.model.Product;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

import java.math.BigDecimal;
import java.util.Date;

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ProductVO {
    private Long id;

    /**
     * 分类ID
     */
    private Long categoryId;

    /**
     * 商品名称
     */
    private String name;

    /**
     * 主图
     */
    private String image;

    /**
     * 图片列表(JSON)
     */
    private String[] images;

    /**
     * 价格
     */
    private BigDecimal price;

    /**
     * 所需积分
     */
    private Integer points;

    /**
     * 商品描述
     */
    private String description;

    /**
     * 购买须知
     */
    private String notice;

    /**
     * 有效期
     */
    private String validityPeriod;

    /**
     * 使用时间
     */
    private String useTime;

    /**
     * 使用地址
     */
    private String address;

    /**
     * 销量
     */
    private Integer soldCount;

    /**
     * 库存
     */
    private Integer stock;

    /**
     * 状态:1上架,2下架
     */
    private Integer status;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;

    public void toProductVo(Product product){
        this.id = product.getId();
        this.name = product.getName();
        this.price = product.getPrice();
        this.points = product.getPoints();
        this.description = product.getDescription();
        this.notice = product.getNotice();
        this.validityPeriod = product.getValidityPeriod();
        this.useTime = product.getUseTime();
        this.address = product.getAddress();
        this.images =product.getImages().split(",");
    }
}
